#include "stdafx.h"
#include "customException.h"
#include <OleAuto.h>

HRESULT CustomException::SetErrorInfoAndReturn(HRESULT hr, REFCLSID clsid)
{
  // Get the ICreateErrorInfo Interface
  ICreateErrorInfo *pCreateErrorInfo = NULL;
  CreateErrorInfo(&pCreateErrorInfo);

  // Fill the error information into it
  pCreateErrorInfo->SetGUID(clsid);
  pCreateErrorInfo->SetDescription(const_cast<LPOLESTR>(strDescription.c_str()));
  pCreateErrorInfo->SetSource(const_cast<LPOLESTR>(strSource.c_str()));

  // Get the IErrorInfo interface
  IErrorInfo *pErrorInfo = NULL;
  pCreateErrorInfo->QueryInterface(IID_IErrorInfo, (void**)&pErrorInfo);
    
  // Set this error information in the current thread
  SetErrorInfo(0, pErrorInfo);

  return hr;
}